"use strict";
cc._RF.push(module, '3499aOWVQZJ5aTD4gFumfkP', 'Untils');
// script/Game/Libs/Untils.ts

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.randByWeight = exports.getRandomIntInclusive = void 0;
//范围数字内随机一个
function getRandomIntInclusive(min, max) {
    min = Math.ceil(min);
    max = Math.floor(max);
    return Math.floor(Math.random() * (max - min + 1)) + min;
}
exports.getRandomIntInclusive = getRandomIntInclusive;
function randByWeight(arr) {
    var totalWeight = 0;
    var randIndex = 0;
    for (var _i = 0, arr_1 = arr; _i < arr_1.length; _i++) {
        var itemWeight = arr_1[_i];
        totalWeight += itemWeight.weight;
    }
    if (totalWeight <= 0) {
        return randIndex;
    }
    else {
        var randVal = getRandomIntInclusive(1, totalWeight);
        for (var index = 0; index < arr.length; index++) {
            if (randVal <= arr[index].weight) {
                randIndex = index;
                break;
            }
            else {
                randVal -= arr[index].weight;
            }
        }
    }
    return randIndex;
}
exports.randByWeight = randByWeight;

cc._RF.pop();